﻿package com.truongnha.clienttn.business.model;

import java.util.ArrayList;
import java.util.List;

import com.truongnha.clienttn.data.entity.StudentMarkEntity;

import config.Setting;

public class ASubjectMarkModel {
	private static final int MAX_COL = Setting.MAX_COL_MARK;
	private List<StudentMarkModel> listMark;
	private int markId;
	private String name;

	public ASubjectMarkModel(List<StudentMarkModel> listMark, int markId,
			String name) {
		super();
		this.listMark = listMark;
		this.markId = markId;
		this.name = name;
	}

	public ASubjectMarkModel(int markId, String name) {
		super();
		listMark = new ArrayList<StudentMarkModel>();
		this.markId = markId;
		this.name = name;
	}

	public int getMarkId() {
		return markId;
	}

	public void setMarkId(int markId) {
		this.markId = markId;
	}

	public String getName() {
		if (name.equals("Giáo dục quốc phòng"))			
			return "GDQP-AN";
		else if (name.equals("Giáo dục công dân"))
			return "GDCD";
		else
			return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void add(StudentMarkModel studentMarkModel) {
		listMark.add(studentMarkModel);
	}

	public void add(StudentMarkEntity studentMarkEntity) {
		StudentMarkModel studentMarkModel = new StudentMarkModel(
				studentMarkEntity);
		listMark.add(studentMarkModel);
	}

	public String normalize(double x) {
		if (Math.abs(x - Math.round(x)) < 0.01)
			return "" + Math.round(x);
		else
			return "" + x;
	}

	public String getMarkToString() {
		String result = "";
		String mieng = "";
		String mLamPhut = "";
		String motTiet = "";
		String cuoiKy = "";
		String tbHocKy1 = "";
		String tbHocKy2 = "";
		String tbCaNam = "";

		for (StudentMarkModel studentMarkModel : listMark) {
			int number = studentMarkModel.getNumber();
			String score = studentMarkModel.getScore();
			if (number <= MAX_COL)
				mieng += score + "  ";
			else if (number <= 2 * MAX_COL)
				mLamPhut += score + "  ";
			else if (number <= 3 * MAX_COL)
				motTiet += score + "  ";
			else if (number == 3 * MAX_COL + 1)
				cuoiKy = score;
			else if (number == 3 * MAX_COL + 2)
				tbHocKy1 = score;
			else if (number == 3 * MAX_COL + 3)
				tbHocKy2 = score;
			else if (number == 3 * MAX_COL + 4)
				tbCaNam = score;
		}
		if (!mieng.isEmpty())
			result += "Miệng: " + mieng;
		if (!mLamPhut.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Điểm 15': " + mLamPhut;
		}
		if (!motTiet.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Một tiết: " + motTiet;
		}
		if (!cuoiKy.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Cuối kỳ: " + cuoiKy;
		}
		if (!tbHocKy1.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Tbhk 1: " + tbHocKy1;
		}
		if (!tbHocKy2.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Tbhk 2: " + tbHocKy2;
		}
		if (!tbCaNam.isEmpty()) {
			if (!result.equals(""))
				result += "\n";
			result += "Tbcn: " + tbCaNam;
		}
		return result;
	}
}
